package chapter3;

import org.junit.jupiter.api.Test;

/**
 * @author ycj
 * @version 1.0
 * @description: TODO
 * @date 2022/5/18
 */


public class Source3_27 {
    @Test
    public void Test() {
        Thread[] threads=new Thread[2];

            threads[0]=new Thread(()->{
              Work4.writer();
            });

            threads[1]=new Thread(()->{
                Work4.reader();
            });

            threads[0].start();
            threads[1].start();
            //1


    }
}

class Work4{
    final int x;
    int y;
    static Work4 work4;

    public Work4() {
        x=2;
        y=1;
    }

    public static void writer(){
        work4=new Work4();
    }

    public static void reader(){
        final Work4 work41=work4;
        if(work41!=null){
            int diff=work41.x-work41.y;
            System.out.println(diff);
        }
    }
}
